package com.huike.stock_analysis.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.huike.stock_analysis.service.DebtService;


/**
 * 
 * @author mzLEI
 * 偿债能力接口
 */
@RestController
@CrossOrigin(value = "*")
@RequestMapping("/debt")
public class DebtController {
	
	@Autowired
	private DebtService dService;
	
	
	//资产负债率
	@RequestMapping("/assetsDebtRatio")
	public String assetsDebtRatio(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = dService.assetsDebtRatio(stock);
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
		
	}
	
	//流动比率
	@RequestMapping("/flowRatio")
	public String flowRatio(String stock) {
		if(stock == null) return "null";
		Map<String, String> map = dService.flowRatio(stock);
		//json对象
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			//封装
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	
	/*
	//流动比率
	@RequestMapping("/speedRatio")
	public String speedRatio(String code) {
		Map<String, String> map = dService.speedRatio("000001");
		//json对象
		ObjectMapper mapper = new ObjectMapper();
		
		String result = "";
		try {
			//封装
			result = mapper.writeValueAsString(map);
		} catch (JsonProcessingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}
	*/
	//产权比率
	@RequestMapping("/equityRatio")
	public String equityRatio(String stock) {
		if(stock == null) return "null";
		return dService.equityRatio(stock);
	}
	
	//资产固定化比率
	@RequestMapping("/fixedAssetsRaito")
	public String fixedAssetsRaito(String stock) {
		if(stock == null) return "null";
		return dService.fixedAssetsRaito(stock);
	}
	
	
	//长期负债比率
	@RequestMapping("/longTermDebtRatio")
	public String longTermDebtRatio(String stock) {
		if(stock == null) return "null";
		return dService.longTermDebtRatio(stock);
	}
	
	//现金比率
	@RequestMapping("/cashRatio")
	public String cashRatio(String stock) {
		if(stock == null) return "null";
		return dService.cashRatioRatio(stock);
	}


	
	

}
